<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@page import="com.wyzz.hr.base.Constants"%>
<%@taglib prefix="s" uri="strutsTags"%>
<script type="text/javascript" src="dwr/interface/MYOT.js"></script>
<div id="dlgOtTotalSummary" style="display: none; width: 600px">
	<table id="otTotalSummary" cellSpacing="0" cellPadding="0" width="100%"
		class="gridview" id="logTable">
		<tr id="totalHead">
			<th align="center">
				加班种类
			</th>
			<th align="center">
				本月累计加班小时数
			</th>
			<th align="center">
				本年累计加班小时数
			</th>
			<th align="center">
				待审小时数
			</th>
		</tr>
		<s:iterator value="otTypeList" status="item">
			<tr>
				<td align="center" id="<s:property value='#item.index'/>_type"></td>
				<td align="center" id="<s:property value='#item.index'/>_totalMonth"></td>
				<td align="center" id="<s:property value='#item.index'/>_totalYear"></td>
				<td align="center" id="<s:property value='#item.index'/>_totalWait"></td>
			</tr>
		</s:iterator>
		<tr>
			<td colspan="4" class="prompt_div_bottom">
				<input class="button" type="button" value="关闭"
					onclick="hrm.common.closeDialog('dlgOtTotalSummary');" />
			</td>
		</tr>
	</table>
</div>
<div id="dlgTiaoxiuTotal" style="display: none; width: 400;">
	<table cellSpacing="0" cellPadding="0" width="100%" class="gridview">
		<tbody id="tiaoxiuTotal">

		</tbody>
	</table>
</div>
<script>
	hrm.common.initDialog('dlgOtTotalSummary'); //请假明细汇总
	hrm.common.initDialog('dlgTiaoxiuTotal'); // 加班调休汇总

	function getOvertimeTotal(empId, actionURL) {
		MYOT.getOverTimeData(empId, actionURL, overtimeTotalCallback);
	}

	function overtimeTotalCallback(result) {
		if (result.error != null) {
			alert(result.error);
			return;
		}
		for ( var i = 0; i < result.param_succ.length; i++) {
			document.getElementById(i + "_type").innerHTML = result.param_succ[i][0];
			document.getElementById(i + "_totalMonth").innerHTML = result.param_succ[i][1];
			document.getElementById(i + "_totalYear").innerHTML = result.param_succ[i][2];
			document.getElementById(i + "_totalWait").innerHTML = result.param_succ[i][3];
		}
		var empName = document.getElementById("empName").value;
		var currYear = document.getElementById("currYear").value;
		hrm.common.openDialog('dlgOtTotalSummary', null, '年度加班汇总(' + empName
				+ '-' + currYear + ')');
	}

	function getTiaoxiu(empId, actionURL) {
		MYOT.getTiaoxiuTime(empId, actionURL, getTiaoxiuCallback);
	}
	function getTiaoxiuCallback(result) {
		var table = document.getElementById("tiaoxiuTotal");

		while (table.firstChild) {
			table.removeChild(table.firstChild);
		}

		if (result.error != null) {
			alert(result.error);
			return;
		}
		var length = result.param_succ.length;

		var tr;
		var td;

		tr = document.createElement("tr");
		for ( var i = 0; i < length; i++) {
			td = document.createElement("td");
			td.setAttribute("colSpan", 6);
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(result.param_succ[i][0]));
			tr.appendChild(td);
		}
		table.appendChild(tr);
		tr = document.createElement("tr");
		for ( var i = 0; i < length; i++) {
			td = document.createElement("td");
			td.setAttribute("colSpan", "2");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode("普通加班"));
			tr.appendChild(td);
			td = document.createElement("td");
			td.setAttribute("colSpan", "2");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode("周末加班"));
			tr.appendChild(td);
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.setAttribute("colSpan", "2");
			td.appendChild(document.createTextNode("节假日加班"));
			tr.appendChild(td);
		}
		table.appendChild(tr);
		tr = document.createElement("tr");
		for ( var i = 0; i < length * 3; i++) {
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode("已用额度"));
			tr.appendChild(td);
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode("剩余额度"));
			tr.appendChild(td);
		}
		table.appendChild(tr);

		tr = document.createElement("tr");
		for ( var i = 0; i < length; i++) {
			var value = result.param_succ[i][1].split("-");
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(value[0]));
			tr.appendChild(td);
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(value[1]));
			tr.appendChild(td);
			value = result.param_succ[i][2].split("-");
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(value[0]));
			tr.appendChild(td);
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(value[1]));
			tr.appendChild(td);
			value = result.param_succ[i][3].split("-");
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(value[0]));
			tr.appendChild(td);
			td = document.createElement("td");
			td.setAttribute("align", "center");
			td.appendChild(document.createTextNode(value[1]));
			tr.appendChild(td);
		}
		table.appendChild(tr);

		$(table)
				.append(
						"<tr><td colspan='"
								+ (length * 6)
								+ "' class='prompt_div_bottom'><input type='button' class='button' value='关闭' onclick='closeTiaoxiuDialog();'/></td></tr>");

		var widthDiv = 400;
		if (length > 2)
			widthDiv += (length - 2) * 200;

		$('#dlgTiaoxiuTotal').dialog("option", "width", widthDiv);
		var empName = document.getElementById("empName").value;
		var currYear = document.getElementById("currYear").value;
		hrm.common.openDialog('dlgTiaoxiuTotal', null, '调休加班汇总(单位:小时)('
				+ empName + '-' + currYear + ')');
	}

	function closeTiaoxiuDialog() {
		hrm.common.closeDialog('dlgTiaoxiuTotal');
	}
</script>